import variable as va
from PIL import Image
import numpy as np
import hogfeature as hog
import joblib
import os

# 处理图片（得到特征）
def dealImage(image):
    # 修改图片大小
    img.resize((va.image_width, va.image_height), Image.ANTIALIAS)
    # 将图片转为数组
    img = np.reshape(img, (va.image_height, va.image_width, 3))
    
    return feat

# 传入图片进行分类
def doClassify(image_path):
    try:
        # 加载模型
        clf = joblib.load(va.model_path + 'model')
    except:
        print('加载模型失败！请检查……')
    else:
        # 加载图片
        img = Image.open(os.path.join(image_path))
        # 处理图片
        img = hog.dealImage(img)
        # 提取特征
        feat = hog.get_feat(img)
        feat = np.concatenate((feat, []))
        # 进行预测
        result = clf.predict([feat])
        return result


if __name__ == '__main__':
    # 加载图片
    image_path = input('请输入图片的路径:')
    # 进行分类
    result = doClassify(image_path)
    print(va.labels[int(result)])
